﻿commons = commons || {};
//公共-Cookie操作
commons.cookie = function () {
    return {
        set: function (name, value) {
            ///<summary>
            ///设置Cookie
            ///</summary>
            var days = 365;
            var exp = new Date();
            exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
            document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
        },
        get: function (name) {
            ///<summary>
            ///获取Cookie
            ///</summary>
            var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
            if (arr = document.cookie.match(reg))
                return unescape(arr[2]);
            else
                return null;
        },
        del: function (name) {
            ///<summary>
            ///删除Cookie
            ///</summary>
            var exp = new Date();
            exp.setTime(exp.getTime() - 1);
            var cval = commons.cookie.get(name);
            if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
        }
    }
}();
